package org.ifilm.service;

import java.util.List;

import org.ifilm.dao.MessageDao;
import org.ifilm.model.Message;
import org.ifilm.model.MessageSubject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 
 * @author Mustafa Genç
 *
 */
@Service
@Transactional
public class MessageServiceImpl implements MessageService {
	@Autowired
	private MessageDao messageDao;

	@Override
	public Message createMessage(Message message) {
		return messageDao.createMessage(message);
	}

	@Override
	public List<MessageSubject> getMessageSubjects(Long userId) {
		return messageDao.getMessageSubjects(userId);
	}

	@Override
	public MessageSubject getMessageSubject(Long messageSubjectId) {
		return messageDao.getMessageSubject(messageSubjectId);
	}

	@Override
	public MessageSubject createMessageSubject(MessageSubject messageSubject) {
		return messageDao.createMessageSubject(messageSubject);
	}

	@Override
	public void updateMessages(MessageSubject messageSubject, Message message) {
		messageSubject.getMessages().add(message);
	}

	@Override
	public List<MessageSubject> getUnreadMessages(Long userId) {
		return messageDao.getUnreadMessages(userId);
	}

	@Override
	public void setRead(MessageSubject messageSubject) {
		messageSubject.setHasUnread(false);
	}
}